package com.raychi.demo.util;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.raychi.demo.entity.Student;
import com.raychi.demo.entity.Teacher;

public class SessionUtil {
	
	public final static String KEY_SESSION_TEACHER = "teacher";
	public final static String KEY_SESSION_STUDENT = "student";
	

	
	public static void setTeacherSession(Teacher teacher) {
		HttpSession session = ServletActionContext.getRequest().getSession(true);
		session.setAttribute(KEY_SESSION_TEACHER, teacher);
	}
	
	public static Teacher getTeacher() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		if (session == null)
			return null;
		return (Teacher) session.getAttribute(KEY_SESSION_TEACHER);
	}
	
	public static void setStudentSession(Student student) {
		HttpSession session = ServletActionContext.getRequest().getSession(true);
		session.setAttribute(KEY_SESSION_STUDENT, student);
	}
	
	public static Student getStudent() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		if (session == null)
			return null;
		return (Student) session.getAttribute(KEY_SESSION_STUDENT);
	}
	
	
}
